package com.itheima.set;

import com.itheima.domain.Student;

import java.util.Comparator;
import java.util.TreeSet;

/*
要求
年龄  从大-> 小
姓名 从 大-> 小

 */
public class Demo03 {

    public static void main(String[] args) {
       /* TreeSet<Student> treeSet = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                //o1 要插入的数据 o2 集合中已有的数据
                //年龄的降序
                int i = o2.getAge() - o1.getAge();
                int result = i == 0 ? o2.getName().compareTo(o1.getName()) : i;
                System.out.println("o1:"+o1.getName()+" VS o2:"+o2.getName());
                System.out.println("pk的结果是"+result);
                //姓名的降序
                return result;
            }
        });*/
        TreeSet<Student> treeSet = new TreeSet<>((o1, o2) ->
                o2.getAge() - o1.getAge() == 0 ? o2.getName().compareTo(o1.getName()) : o2.getAge() - o1.getAge()
        );
        Student wu = new Student("wuyifan", 31);
        Student huang = new Student("huangzitao", 31);
        Student lu = new Student("luhan", 30);
        Student zhang = new Student("zhangyixing", 31);
        treeSet.add(wu);
        treeSet.add(huang);
        treeSet.add(lu);
        treeSet.add(zhang);
        System.out.println(treeSet);


    }
}
